<?php

/*

  Action	$3

  +$2
  You may immediately put your deck into your discard pile.

 */

class Chancellor extends Card implements iAction, iKingdom, iBasic {

    private $discardedCards;

    public function __construct() {
        parent::__construct("Chancellor", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+$2",
            "You may immediately put your deck into your discard pile.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addMoney(new Price(2));
        ScreenDisplay::addScreenMessage($game, true, "get +2$", "gets +2$");

        $options = array(new Option(1, "Yes"), new Option(2, "No"));

        $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Put draw pile in discard?");

        $answer = $output[0];
        if ($answer == "Yes") {
            $this->discardedCards = $game->getDrawDeck();
            $game->putDrawPileInDiscard();
            ScreenDisplay::addScreenMessage($game, false, " and discard  your deck ", " and discards his deck");
        } else {
            $this->discardedCards = array();
            ScreenDisplay::addScreenMessage($game, false, " and leave  your deck as is ", " and leaves his deck as is");
        }
        $game->cardActionFinished();
        return true;
    }

    public function undoParamsPlay($undoParams) {
        $undoParams['discardedCards'] = $this->discardedCards;
        return array($this->undoPlay, $undoParams);
    }

    public function undo(Game $game, $undoParams) {
        $discardedCards = $undoParams['discardedCards'];
        $discardedCards = array_reverse($discardedCards);
        foreach ($discardedCards as $card) {
            $game->undo_func_moveCardFromPileToPile($card, DiscardPile, DrawPile);
        }
        $game->addMoney(new Price(-2));
    }

}

?>